/**
 * jims
 */
package com.jims.master.modules.orders.entity;

import com.fasterxml.jackson.annotation.JsonBackReference;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.jims.master.common.persistence.DataEntity;
import com.jims.master.common.utils.StringUtils;
import com.jims.master.common.web.impl.BaseDto;
import com.jims.master.modules.orders.vo.OrdersOper;
import com.jims.master.modules.reg.utils.DateUtil;
import com.jims.master.modules.sys.entity.PerformFreqDict;
import com.jims.master.modules.sys.utils.UserUtils;
import org.hibernate.validator.constraints.Length;

import java.beans.Transient;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;

/**
 * 遗嘱Entity
 *
 * @author 陈晓阳
 * @version 2017-03-27
 */
public class Orders extends DataEntity<Orders> {

    private static final long serialVersionUID = 1L;
    private String patientId;        // 病人Id
    private String visitId;        // 住院Id
    private Orders parent;        // 父遗嘱Id
    private String orderText;        // 遗嘱内容
    private String orderClass;        // 医嘱类别
    private String orderStatus;        // 医嘱状态
    private String billingAttr;        // 计价属性
    private Date startDate;        // 开始时间
    private Date stopDate;        // 结束时间
    private Date lastAcctingDate;        // 上次计价时间
    private Date lastDispDate;        // 上次摆药时间
    private String repeatIncaditor;        // 临时长期标志
    private double singleDose;        // 单次剂量
    private String singleDoseUnit;        // 单次剂量单位
    private String administration;        // 途径
    private String performFreq;        // 频次字典表主键
    private String isApply;        // 申请号
    private String doctInstruction;        // 医生说明
    private String newDept;        // 开单科室
    private String copiedNurse;        // 转抄护士
    private Date copiedDate;        // 转抄时间
    private String checkNurse;        // 校对护士
    private Date checkDate;        // 校对时间
    private String stopDoct;        // 停止医生
    private Date stopInDate;        // 停止录入日期
    private String nursePerformTime;        // nurse_perform_time
    private PerformFreqDict performFreqDict;
    private String startTime;
    private String endTime;
    private String clinicItemId;//诊疗项目Id
    private String performedBy;//执行科室
    private List<String> ids = new ArrayList<String>();
    private String isDrug;
    private String drugSpec;//药品规格--包装规格
    private String firmId;//厂商
    private List<Orders> children = new ArrayList<Orders>();//子医嘱
    //查询条件
    private String bedNo;
    private String type;//执行单类型
    private String adminis;
    private String name;
    private String deptName;
    private String freqDesc;
    private String wardCode;
    private Integer pageFlag;
    //临时属性
    private List<String> admList;
    private Integer stock;//药品库存
    private Date preDischargeDate;//预出院时间
    private String drugUnits;//包装单位
    private String drugName;//药品名称
    private String drugCode;//药品code
    private String minSpec;//最小规格
    private String minUnits;//最小单位
    private double freqCounter = 0;
    private double freqInterval = 0;
    private String freqIntervalUnit;
    private Integer days;
    private Date currentDispEndDate;
    private SimpleDateFormat ymds = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    private SimpleDateFormat ymd = new SimpleDateFormat("yyyy-MM-dd");
    private String storageId;
    private double dosePerUnit;
    private String visitNo;
    private String dispNo;
    private String classOnMr;
    private double price;
    private String classOnRcpt;
    private String classOnReckoning;
    private String subjCode;
    private String firmName;
    private String newDoct;
    private Integer packageNum;
    private String applyId;
    private String currentUserId;
    private String isPresc;
    private String tempalteId;
    private List<Orders> list;
    private String prescNo;
    private Date nurseStopTime;
    private Date executeDateTime;
    private String isExecute;
    private String rebuteNurse;
    private Date rebuteDateTime;
    private String rebuteRemarks;
    private String stopNurse;

    private String administrationTypeName;

    private String orderDrugText;
    private String orderClinicText;
    private String orderEntrustText;
    private String zcFlag;
    private String jdFlag;
    private String packageUnits;
    private String executeNurse;
    private String doseUnits;
    private double stockNum;
    private Date createDate;
    private Date endDate;
    private String timestamp;
    private String confDate;
    public static String COLUMN="create_date";
    public static Integer MM=6;
    private List<BaseDto> confs=new ArrayList<BaseDto>();
    public Date getEndDate() {
        return endDate;
    }

    public void setEndDate(Date endDate) {
        this.endDate = endDate;
    }

    public Date getCreateDate() {
        return createDate;
    }

    public void setCreateDate(Date createDate) {
        this.createDate = createDate;
    }

    public double getStockNum() {
        return stockNum;
    }

    public void setStockNum(double stockNum) {
        this.stockNum = stockNum;
    }

    public String getDoth() {
        String returnVal="";
        if(StringUtils.isNotBlank(this.repeatIncaditor)&&"2".equals(this.orderStatus)){
              returnVal="待校对";
        }
        if(StringUtils.isNotBlank(this.repeatIncaditor)&&"6".equals(this.orderStatus)&&"0".equals(this.repeatIncaditor)){
            returnVal="待执行";
        }
        return returnVal;
    }



    public String getPackageUnits() {
        return packageUnits;
    }

    public void setPackageUnits(String packageUnits) {
        this.packageUnits = packageUnits;
    }

    public String getZcFlag() {
        return zcFlag;
    }

    public void setZcFlag(String zcFlag) {
        this.zcFlag = zcFlag;
    }

    public String getJdFlag() {
        return jdFlag;
    }

    public void setJdFlag(String jdFlag) {
        this.jdFlag = jdFlag;
    }

    public String getExecuteNurse() {
        return executeNurse;
    }

    public void setExecuteNurse(String executeNurse) {
        this.executeNurse = executeNurse;
    }

    public String getOrderDrugText() {
        return orderDrugText;
    }

    public void setOrderDrugText(String orderDrugText) {
        this.orderDrugText = orderDrugText;
    }

    public String getOrderClinicText() {
        return orderClinicText;
    }

    public void setOrderClinicText(String orderClinicText) {
        this.orderClinicText = orderClinicText;
    }

    public String getOrderEntrustText() {
        return orderEntrustText;
    }

    public void setOrderEntrustText(String orderEntrustText) {
        this.orderEntrustText = orderEntrustText;
    }

    public String getAdministrationTypeName() {
        return administrationTypeName;
    }

    public void setAdministrationTypeName(String administrationTypeName) {
        this.administrationTypeName = administrationTypeName;
    }


    public String getIsPresc() {
        return isPresc;
    }

    public void setIsPresc(String isPresc) {
        this.isPresc = isPresc;
    }

    public List<Orders> getList() {
        return list;
    }

    public void setList(List<Orders> list) {
        this.list = list;
    }

    public String getTempalteId() {
        return tempalteId;
    }

    public void setTempalteId(String tempalteId) {
        this.tempalteId = tempalteId;
    }

    public Integer getPackageNum() {
        return packageNum;
    }

    public void setPackageNum(Integer packageNum) {
        this.packageNum = packageNum;
    }

    public String getNewDoct() {
        return newDoct;
    }

    public void setNewDoct(String newDoct) {
        this.newDoct = newDoct;
    }

    public String getFirmName() {
        return firmName;
    }

    public void setFirmName(String firmName) {
        this.firmName = firmName;
    }

    public String getClassOnMr() {
        return classOnMr;
    }

    public void setClassOnMr(String classOnMr) {
        this.classOnMr = classOnMr;
    }

    public String getDispNo() {
        return dispNo;
    }

    public void setDispNo(String dispNo) {
        this.dispNo = dispNo;
    }

    public double getPrice() {
        return price;
    }

    public void setPrice(double price) {
        this.price = price;
    }

    public String getVisitNo() {
        return visitNo;
    }

    public void setVisitNo(String visitNo) {
        this.visitNo = visitNo;
    }

    public String getClassOnRcpt() {
        return classOnRcpt;
    }

    public void setClassOnRcpt(String classOnRcpt) {
        this.classOnRcpt = classOnRcpt;
    }

    public String getClassOnReckoning() {
        return classOnReckoning;
    }

    public void setClassOnReckoning(String classOnReckoning) {
        this.classOnReckoning = classOnReckoning;
    }

    public String getSubjCode() {
        return subjCode;
    }

    public void setSubjCode(String subjCode) {
        this.subjCode = subjCode;
    }


    public double getDosePerUnit() {
        return dosePerUnit;
    }

    public void setDosePerUnit(double dosePerUnit) {
        this.dosePerUnit = dosePerUnit;
    }

    public String getMinSpec() {
        return minSpec;
    }

    public void setMinSpec(String minSpec) {
        this.minSpec = minSpec;
    }

    public String getMinUnits() {
        return minUnits;
    }

    public void setMinUnits(String minUnits) {
        this.minUnits = minUnits;
    }

    public String getStorageId() {
        return storageId;
    }

    public void setStorageId(String storageId) {
        this.storageId = storageId;
    }

    public Integer getDays() {
        return days;
    }

    public void setDays(Integer days) {
        this.days = days;
    }

    public Orders() {
        super();
    }

    public Orders(String id) {
        super(id);
    }

    @Length(min = 1, max = 64, message = "病人Id长度必须介于 1 和 64 之间")
    public String getPatientId() {
        return patientId;
    }

    public void setPatientId(String patientId) {
        this.patientId = patientId;
    }

    @Length(min = 1, max = 64, message = "住院Id长度必须介于 1 和 64 之间")
    public String getVisitId() {
        return visitId;
    }

    public void setVisitId(String visitId) {
        this.visitId = visitId;
    }

    @JsonBackReference
    public Orders getParent() {
        return parent;
    }

    public void setParent(Orders parent) {
        this.parent = parent;
    }

    @Length(min = 1, max = 64, message = "遗嘱内容长度必须介于 1 和 64 之间")
    public String getOrderText() {
        return orderText;
    }

    public void setOrderText(String orderText) {
        this.orderText = orderText;
    }

    @Length(min = 1, max = 1, message = "医嘱类别长度必须介于 1 和 1 之间")
    public String getOrderClass() {
        return orderClass;
    }

    public void setOrderClass(String orderClass) {
        this.orderClass = orderClass;
    }


    public void setOrderStatus(String orderStatus) {
        this.orderStatus = orderStatus;
    }

    @Length(min = 1, max = 11, message = "计价属性-sys-dict主键长度必须介于 1 和 11 之间")
    public String getBillingAttr() {
        return billingAttr;
    }

    public void setBillingAttr(String billingAttr) {
        this.billingAttr = billingAttr;
    }

    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    public Date getStartDate() {
        return startDate;
    }

    public void setStartDate(Date startDate) {
        this.startDate = startDate;
    }

    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    public Date getStopDate() {
        return stopDate;
    }

    public void setStopDate(Date stopDate) {
        this.stopDate = stopDate;
    }

    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    public Date getLastAcctingDate() {
        return lastAcctingDate;
    }

    public void setLastAcctingDate(Date lastAcctingDate) {
        this.lastAcctingDate = lastAcctingDate;
    }

    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    public Date getLastDispDate() {
        return lastDispDate;
    }

    public void setLastDispDate(Date lastDispDate) {
        this.lastDispDate = lastDispDate;
    }

    @Length(min = 0, max = 1, message = "临时长期标志长度必须介于 0 和 1 之间")
    public String getRepeatIncaditor() {
        return repeatIncaditor;
    }

    public void setRepeatIncaditor(String repeatIncaditor) {
        this.repeatIncaditor = repeatIncaditor;
    }

    public double getSingleDose() {
        if("".equals(this.singleDose))
            return 0;
            return singleDose;
    }

    public void setSingleDose(double singleDose) {
        this.singleDose = singleDose;
    }

    @Length(min = 0, max = 10, message = "单次剂量单位长度必须介于 0 和 10 之间")
    public String getSingleDoseUnit() {
        return singleDoseUnit;
    }

    public void setSingleDoseUnit(String singleDoseUnit) {
        this.singleDoseUnit = singleDoseUnit;
    }

    @Length(min = 0, max = 64, message = "途径长度必须介于 0 和 64 之间")
    public String getAdministration() {
        return administration;
    }

    public void setAdministration(String administration) {
        this.administration = administration;
    }

    @Length(min = 0, max = 64, message = "频次字典表主键长度必 须介于 0 和 64 之间")
    public String getPerformFreq() {
        return performFreq;
    }

    public void setPerformFreq(String performFreq) {
        this.performFreq = performFreq;
    }

    @Length(min = 1, max = 1, message = "申请号长度必须介于 1 和 1 之间")
    public String getIsApply() {
        return isApply;
    }

    public void setIsApply(String isApply) {
        this.isApply = isApply;
    }

    @Length(min = 0, max = 200, message = "医生说明长度必须介于 0 和 200 之间")
    public String getDoctInstruction() {
        return doctInstruction;
    }

    public void setDoctInstruction(String doctInstruction) {
        this.doctInstruction = doctInstruction;
    }

    @Length(min = 0, max = 64, message = "开单科室长度必须介于 0 和 64 之间")
    public String getNewDept() {
        return newDept;
    }

    public void setNewDept(String newDept) {
        this.newDept = newDept;
    }

    @Length(min = 0, max = 64, message = "转抄护士长度必须介于 0 和 64 之间")
    public String getCopiedNurse() {
        return copiedNurse;
    }

    public void setCopiedNurse(String copiedNurse) {
        this.copiedNurse = copiedNurse;
    }

    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    public Date getCopiedDate() {
        return copiedDate;
    }

    public void setCopiedDate(Date copiedDate) {
        this.copiedDate = copiedDate;
    }

    @Length(min = 0, max = 64, message = "校对护士长度必须介于 0 和 64 之间")
    public String getCheckNurse() {
        return checkNurse;
    }

    public void setCheckNurse(String checkNurse) {
        this.checkNurse = checkNurse;
    }

    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    public Date getCheckDate() {
        return checkDate;
    }

    public void setCheckDate(Date checkDate) {
        this.checkDate = checkDate;
    }

    @Length(min = 0, max = 64, message = "停止医生长度必须介于 0 和 64 之间")
    public String getStopDoct() {
        return stopDoct;
    }

    public void setStopDoct(String stopDoct) {
        this.stopDoct = stopDoct;
    }

    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    public Date getStopInDate() {
        return stopInDate;
    }

    public void setStopInDate(Date stopInDate) {
        this.stopInDate = stopInDate;
    }


    public String getOrderStatus() {
        return orderStatus;
    }

    @Transient
    public String getOrderStatusTran() {
        if ("0".equals(orderStatus)) {
            return "<font color='blue'>新开</font>";
        } else if ("1".equals(orderStatus)) {
            return "<font color='#90EE90'>传输</font>";
        } else if ("2".equals(orderStatus)) {
            return "<font color='#90CD0'>转抄</font>";
        } else if ("3".equals(orderStatus)) {
            return "<font color='#ccc'>临时执行</font>";
        } else if ("4".equals(orderStatus)) {
            return "<font color='#FFA54F'>停止</font>";
        } else if ("7".equals(orderStatus)) {
            return "<font color='red'>护士驳回</font>";
        } else if ("6".equals(orderStatus)) {
            if(StringUtils.isNotBlank(this.repeatIncaditor)){
                if("0".equals(this.repeatIncaditor)){
                    return "<font color='#8458B'>校对</font>";
                }else{
                    return "<font color='#8458B'>执行</font>";
                }
            }else{
                return "";
            }
        }else if ("8".equals(orderStatus)) {
            return "<font color='#8479B'>医生停止</font>";
        } else {
            return "";
        }
    }

    @Transient
    public String getIsApplyTran() {
        if ("1".equals(this.isApply)) {
            return "申请";
        } else {
            if (this.getParent() != null && this.getParent().getId() != null && !"".equals(this.getParent().getId())) {
                return "子录入";
            } else {
                return "录入";
            }
        }
    }

    @Transient
    public String getIsDrugTran() {
        if ("A".equals(this.orderClass)) {
            return "药品";
        } else {
            if (this.orderClass == null || "".equals(this.orderClass)) {
                return "嘱托类";
            }
            return "非药品";
        }
    }

    @Transient
    public String getRepeatIncaditorTran() {
        if ("0".equals(repeatIncaditor))
            return "临时";
        return "长期";
    }


    @Transient
    public String getIsChild() {
        Orders orders = this.getParent();
        if (orders != null && orders.getId() != null)
            return "0";
        return "1";
    }


    public PerformFreqDict getPerformFreqDict() {
        return performFreqDict;
    }

    public void setPerformFreqDict(PerformFreqDict performFreqDict) {
        this.performFreqDict = performFreqDict;
    }


    public String getStartTime() {
        return startTime;
    }

    public void setStartTime(String startTime) {
        this.startTime = startTime;
    }

    public String getEndTime() {
        return endTime;
    }

    public void setEndTime(String endTime) {
        this.endTime = endTime;
    }

    public String getClinicItemId() {
        return clinicItemId;
    }

    public void setClinicItemId(String clinicItemId) {
        this.clinicItemId = clinicItemId;
    }


    public List<String> getIds() {
        return ids;
    }

    public void setIds(List<String> ids) {
        this.ids = ids;
    }

    public String getIsDrug() {
        return isDrug;
    }

    public void setIsDrug(String isDrug) {
        this.isDrug = isDrug;
    }

    public String getDrugSpec() {
        return drugSpec;
    }

    public void setDrugSpec(String drugSpec) {
        this.drugSpec = drugSpec;
    }

    public String getFirmId() {
        return firmId;
    }

    public void setFirmId(String firmId) {
        this.firmId = firmId;
    }

    public List<Orders> getChildren() {
        return children;
    }

    public void setChildren(List<Orders> children) {
        this.children = children;
    }

    public String getNursePerformTime() {
        return nursePerformTime;
    }

    public void setNursePerformTime(String nursePerformTime) {
        this.nursePerformTime = nursePerformTime;
    }

    public String getBedNo() {
        return bedNo;
    }

    public void setBedNo(String bedNo) {
        this.bedNo = bedNo;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getDeptName() {
        return deptName;
    }

    public void setDeptName(String deptName) {
        this.deptName = deptName;
    }

    public String getFreqDesc() {
        return freqDesc;
    }

    public void setFreqDesc(String freqDesc) {
        this.freqDesc = freqDesc;
    }

    @Transient
    public Integer getAbledperformFlag() {
        if ("6".equals(this.orderStatus) && ("0".equals(this.repeatIncaditor))&& "0".equals(this.delFlag)) {
            return 0;
        } else if ("2".equals(this.orderStatus)&& "0".equals(this.delFlag)) {
            return 1;
        }else{
            return 3;
        }
    }



    public Integer getPageFlag() {
        return pageFlag;
    }

    public void setPageFlag(Integer pageFlag) {
        this.pageFlag = pageFlag;
    }

    public String getWardCode() {
        return wardCode;
    }

    public void setWardCode(String wardCode) {
        this.wardCode = wardCode;
    }

    public String getPerformedBy() {
        return performedBy;
    }

    public void setPerformedBy(String performedBy) {
        this.performedBy = performedBy;
    }

    public Integer getStock() {
        return stock;
    }

    public void setStock(Integer stock) {
        this.stock = stock;
    }

    public Date getPreDischargeDate() {
        return preDischargeDate;
    }

    public void setPreDischargeDate(Date preDischargeDate) {
        this.preDischargeDate = preDischargeDate;
    }


    public Date getStartDispDate() {
        Date returnVal = null;
        if (isFirstDisp() && isLongOrders()) {
            returnVal = startDate;
        } else if (!isFirstDisp() && isLongOrders()) {
            if (new Date().getTime() > lastDispDate.getTime()) {
                returnVal = getNowDayZero(0);
            } else {
                returnVal = lastDispDate;
            }
        }
        return returnVal;
    }


    public Date getEndDispDate() {
        Date returnVal = null;
        if (isHasPreDisCharge() && isLongOrders()) {
            if (getEndDayZero().getTime() >= this.preDischargeDate.getTime()) {
                returnVal = preDischargeDate;
            } else {
                returnVal = getEndDayZero();
            }
        } else if (!isHasPreDisCharge() && isLongOrders()) {
            returnVal = getEndDayZero();
        }
        return returnVal;
    }


    public double getTimes() {
        double returnVal = 0;
        if (isLongOrders()&&isLastDisp()) {
            if (isHoures()) {
                returnVal = getTimesByHoures();
            } else if (isDay()) {
                returnVal = getTimesByDays();
            } else if (isWeek()) {
                returnVal = getTimesByWeek();
            }
        }else{
            returnVal = 1;
        }
        if(!isLastDisp()){
            returnVal = 0;
        }
        if (returnVal > 0) {
            this.setCurrentDispEndDate(getEndDispDate());
        }
        return returnVal;
    }




    public double getTimesByWeek() {
        double returnVal = 0;
        Calendar calendar = Calendar.getInstance();
        Date beginDate = getStartDispDate();
        Date endDate = getEndDispDate();
        List<Integer> days = new ArrayList<Integer>();
        if (this.nursePerformTime == null || "".equals(nursePerformTime)) {
            return 0;
        }
        for (String str : this.nursePerformTime.split("-")) {
            days.add(Integer.parseInt(str));
        }
        if(beginDate==null || endDate==null){
            return 0;
        }
        calendar.setTime(beginDate);

        while (beginDate.getTime() < endDate.getTime()) {
            int day = calendar.get(Calendar.DAY_OF_WEEK) - 1;
            if (days.contains(day)) {
                returnVal += 1;
            }
            calendar.add(Calendar.DAY_OF_MONTH, 1);
            beginDate = calendar.getTime();
        }
        return returnVal;
    }


    public double getTimesByDays() {
        double returnVal = 0;
        if (isBetweenDay()) {
            int bdays = 0;
            try {
                bdays = DateUtil.daysBetween(this.getStartDispDate(), getEndDispDate());
            } catch (ParseException e) {
                e.printStackTrace();
            }
            Float f = (float) bdays / (float) 2f;
            if(0==f.intValue()){
                if(!ymds.format(this.getStartDispDate()).contains("23:59:59")){
                    returnVal = 1;
                }
            }else{
                 for(int i=1;i<=bdays;i++){
                     Float g=(float) i/(float)2f;
                     if(g==g.intValue()){
                         returnVal++;
                     }
                 }
            }
        } else {
            returnVal = oneDayN();
        }
        return returnVal;
    }


    public double oneDayN() {
        double returnVal = 0;
        Date beginDate = getStartDispDate();
        Date endDate = getEndDispDate();
        if (this.nursePerformTime == null || beginDate == null || endDate == null) {
            return 0;
        }
        String[] times = this.nursePerformTime.split("-");
        if(times.length==0){
            return returnVal;
        }
        Calendar calendar = Calendar.getInstance();
        List<Integer> hours = new ArrayList<Integer>();
        for (String str : times) {
            hours.add(Integer.parseInt(str));
        }
        while (beginDate.getTime() < endDate.getTime()) {
            calendar.setTime(beginDate);
            int hour = calendar.get(Calendar.HOUR_OF_DAY);
            if (hours.contains(hour)) {
                returnVal += 1;
            }
            calendar.add(Calendar.HOUR_OF_DAY, 1);
            beginDate = calendar.getTime();
        }
        return returnVal;
    }

    public double getTimesByHoures() {
        double returnVal = 0;
        if (getStartDispDate() == null || getEndDispDate() == null || freqInterval == 0) {
            return returnVal;
        }
        try {
            returnVal = (DateUtil.hourBetween(getStartDispDate(), getEndDispDate())) / freqInterval;
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return returnVal;
    }


    public double getAmount() {
        double returnVal = 0;
        double times = getTimes();
        if (times > 0) {
            Double minAmount = this.singleDose / this.dosePerUnit;
            if (this.drugSpec.equals(this.minSpec)) {
                Double temp = minAmount * times;
                returnVal = temp.intValue() < 1 ? 1 : temp.intValue();
            } else {
                if(packageNum==null){
                    return returnVal;
                }
                Double r = (minAmount / packageNum) * times;
                returnVal = r.intValue() < 1 ? 1 : r.intValue();
            }
        }
        return returnVal;
    }


    public Date getNowDayZero(int flag) {
        String now = ymd.format(new Date());
        Date result = null;
        try {
            if (0 == flag) {
                result = ymds.parse(now + " 00:00:00");
            } else {
                result = ymds.parse(now + " 23:59:59");
            }
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return result;
    }

    public Date getEndDayZero() {
        if (days != null) {
            if (1 == days)
                return getNowDayZero(1);
            return DateUtil.getDaysAfter(getNowDayZero(1), days - 1);
        } else {
            return null;
        }
    }

    public String getDrugUnits() {
        return drugUnits;
    }

    public void setDrugUnits(String drugUnits) {
        this.drugUnits = drugUnits;
    }

    public String getDrugName() {
        return drugName;
    }

    public void setDrugName(String drugName) {
        this.drugName = drugName;
    }

    public String getDrugCode() {
        return drugCode;
    }

    public void setDrugCode(String drugCode) {
        this.drugCode = drugCode;
    }

    public double getFreqCounter() {
        return freqCounter;
    }

    public void setFreqCounter(double freqCounter) {
        this.freqCounter = freqCounter;
    }

    public double getFreqInterval() {
        return freqInterval;
    }

    public void setFreqInterval(double freqInterval) {
        this.freqInterval = freqInterval;
    }

    public String getFreqIntervalUnit() {
        return freqIntervalUnit;
    }

    public void setFreqIntervalUnit(String freqIntervalUnit) {
        this.freqIntervalUnit = freqIntervalUnit;
    }


    public boolean isFirstDisp() {
        if (this.lastDispDate == null || "".equals(this.lastDispDate))
            return true;
        return false;
    }


    public boolean isLongOrders() {
        if ("0".equals(this.repeatIncaditor))
            return false;
        return true;
    }


    public boolean isHasPreDisCharge() {
        if (this.preDischargeDate != null && !"".equals(this.preDischargeDate))
            return true;
        return false;
    }


    public boolean isHoures() {
        if (this.freqIntervalUnit != null) {
            if (this.freqIntervalUnit.contains("时")) {
                return true;
            } else {
                return false;
            }
        } else {
            return false;
        }
    }


    public boolean isDay() {
        if (this.freqIntervalUnit != null) {
            if (this.freqIntervalUnit.contains("日")) {
                return true;
            } else {
                return false;
            }
        } else {
            return false;
        }
    }


    public boolean isWeek() {
        if (this.freqIntervalUnit != null) {
            if (this.freqIntervalUnit.contains("周")) {
                return true;
            } else {
                return false;
            }
        } else {
            return false;
        }
    }


    public boolean isBetweenDay() {
        if (freqInterval != 0 && freqCounter != 0) {
            if (2 == this.freqInterval && 1 == freqCounter) {
                return true;
            } else {
                return false;
            }
        } else {
            return false;
        }

    }


    public Boolean isTodayFee() {
        if (isDay() && isBetweenDay()) {
            try {
                int bdays = DateUtil.daysBetween(this.getStartDispDate(),getEndDispDate());
                Float f = (float) bdays / (float) 2f;
                if (f == f.intValue()) {
                    return true;
                } else {
                    return false;
                }
            } catch (ParseException e) {
                e.printStackTrace();
            }
        }
        return false;
    }

    public Date getCurrentDispEndDate() {
        return currentDispEndDate;
    }

    public void setCurrentDispEndDate(Date currentDispEndDate) {
        this.currentDispEndDate = currentDispEndDate;
    }


    public String getApplyId() {
        return applyId;
    }

    public void setApplyId(String applyId) {
        this.applyId = applyId;
    }

    public String getCurrentUserId() {
        return currentUserId;
    }

    public void setCurrentUserId(String currentUserId) {
        this.currentUserId = currentUserId;
    }

    public String getType() {
        return type;
    }

    public void setType(String type) {
        this.type = type;
    }

    public List<String> getAdmList() {
        return admList;
    }

    public void setAdmList(List<String> admList) {
        this.admList = admList;
    }

    public String getAdminis() {
        return adminis;
    }

    public void setAdminis(String adminis) {
        this.adminis = adminis;
    }

    public String getPrescNo() {
        return prescNo;
    }

    public void setPrescNo(String prescNo) {
        this.prescNo = prescNo;
    }

    public Date getNurseStopTime() {
        return nurseStopTime;
    }

    public void setNurseStopTime(Date nurseStopTime) {
        this.nurseStopTime = nurseStopTime;
    }

    public Date getExecuteDateTime() {
        return executeDateTime;
    }

    public void setExecuteDateTime(Date executeDateTime) {
        this.executeDateTime = executeDateTime;
    }

    public String getIsExecute() {
        return isExecute;
    }

    public void setIsExecute(String isExecute) {
        this.isExecute = isExecute;
    }

    public String getRebuteNurse() {
        return rebuteNurse;
    }

    public void setRebuteNurse(String rebuteNurse) {
        this.rebuteNurse = rebuteNurse;
    }

    public Date getRebuteDateTime() {
        return rebuteDateTime;
    }

    public void setRebuteDateTime(Date rebuteDateTime) {
        this.rebuteDateTime = rebuteDateTime;
    }

    public String getRebuteRemarks() {
        return rebuteRemarks;
    }

    public void setRebuteRemarks(String rebuteRemarks) {
        this.rebuteRemarks = rebuteRemarks;
    }

    public String getStopNurse() {
        return stopNurse;
    }

    public void setStopNurse(String stopNurse) {
        this.stopNurse = stopNurse;
    }


    public OrdersOper getOrdersOper(){
        OrdersOper returnVal=null;
        switch (this.orderStatus){
            case "0":
                returnVal=OrdersOper.医生新开;
                break;
            case "1":
                returnVal=OrdersOper.医生传输;
                break;
            case "2":
                returnVal=OrdersOper.护士转抄;
                break;
            case "3":
                returnVal=OrdersOper.护士临时执行;
                break;
            case "4":
                returnVal=OrdersOper.护士停止;
                break;
            case "6":
                returnVal=OrdersOper.护士校对;
                break;
            case "7":
                returnVal=OrdersOper.护士驳回;
                break;
            case "8":
                returnVal=OrdersOper.医生停止;
                break;
            default:
                returnVal=OrdersOper.医生删除;
                break;
        }
        return returnVal;
    }
    public boolean isLastDisp(){
        boolean returnVal=false;
        String d1=getTimestampTran();
            try {
                Date one = ymds.parse(d1);
                returnVal = one.getTime()<1514736000000l;
            } catch (ParseException e) {
                e.printStackTrace();
            }
        return returnVal;
    }
    public void setData() {
       if(this.getOrdersOper().equals(OrdersOper.医生传输)){

       }else if(this.getOrdersOper().equals(OrdersOper.护士转抄)){
             setCopiedNurse(UserUtils.getUser().getId());
             setCopiedDate(new Date());
        }else if(this.getOrdersOper().equals(OrdersOper.护士校对)){
            setCheckDate(new Date());
            setCheckNurse(UserUtils.getUser().getId());
            setStartDate(new Date());
            if(StringUtils.isNotBlank(this.repeatIncaditor)&&"1".equals(this.repeatIncaditor)){
                setIsExecute("1");
            }
       }else if(this.getOrdersOper().equals(OrdersOper.护士临时执行)){
            setExecuteDateTime(new Date());
            setIsExecute("1");
            setExecuteNurse(UserUtils.getUser().getId());
       }else if(this.getOrdersOper().equals(OrdersOper.护士驳回)){
            setRebuteDateTime(new Date());
            setRebuteNurse(UserUtils.getUser().getId());
       }else if(this.getOrdersOper().equals(OrdersOper.护士停止)){
            setStopNurse(UserUtils.getUser().getId());
            setNurseStopTime(new Date());
            setStopDate(new Date());
       }else if(this.getOrdersOper().equals(OrdersOper.医生停止)){
            setStopDoct(UserUtils.getUser().getId());
            setStopInDate(new Date());
       }else if(this.getOrdersOper().equals(OrdersOper.医生删除)){
            setDelFlag("1");
       }
    }

    public String getDoseUnits() {
        return doseUnits;
    }

    public void setDoseUnits(String doseUnits) {
        this.doseUnits = doseUnits;
    }

    @Transient
    public String[] getAdministrationes() {
        String[] returnVal=null;
        if(StringUtils.isNotBlank(administration)){
                switch (administration){
                    case "1":
                    returnVal=new String[]{"8ffdf249d701488ba26495774bf090a4","4f3462718c184e1581d37c4ceeb801c3","4fed7cbe885241648702b9f4a97a988d","3764148a89684ca8931c17e4f4074afd"};
                    break;
                    case "2":
                    returnVal=new String[]{"a3f55819e7374b0e8931abb40be097fb","0df9020b4096497e9419d7a7a1c5cb6e","20fbe01b944e4f80b85064f9cf07c461","20fbe01b944e4f80b85064f9cf07c461"};
                    break;
                    case "3":
                    returnVal=new String[]{"0c04b69c87104456b28ae3a3d5d983c3","0c04b69c87104456b28ae3a3d5d983c3","a3f55819e7374b0e8931abb40be097fb","5f2fafd562d54d2aae03cf93021edd21","88ff0567d1364feeadf50fdb03beea3c","5abf6eb45a8941698f9169649011f92c"};
                    break;
                    default:returnVal=null;
                }
        }
        return returnVal;
    }

    public String getTimestamp() {
        return this.timestamp;
    }

    public String getTimestampTran() {
        if(StringUtils.isNotBlank(this.timestamp)){
            SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            Long time=new Long(timestamp);
            String d = format.format(time);
            return d;
        }
        return "";
    }
    public void setTimestamp(String timestamp) {
        this.timestamp = timestamp;
    }

    public String getConfDate() {
        return confDate;
    }

    public void setConfDate(String confDate) {
        this.confDate = confDate;
    }


}